/*
* @Author: Turbidsoul Chen
* @Date:   2016-01-19 18:29:07
* @Last Modified by:   Turbidsoul
* @Last Modified time: 2017-01-14 23:20:35
*/

'use strict';
import webpack from 'webpack';
import ExtractTextPlugin from 'extract-text-webpack-plugin'
const CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
const UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;

export default {
  devtool: "eval",
  entry:  {
    app: [
      'react-hot-loader/patch',
      'webpack-dev-server/client?http://localhost:3000',
      'webpack/hot/only-dev-server',
      './src/index.jsx',
    ]
  },
  resolve: {
    extensions: ['.js', '.json', '.css', '.jsx', '.sass', '.scss']
  },
  output: {
    path: '/dist',
    filename: "[name].js",
    sourceMapFilename: "[name].map",
    chunkFilename: '[id].chunk.js',
  },
  module: {
    loaders: [
      {
        test: /\.css$/,
        loaders: ['style-loader', 'css-loader']
      },
      {
        test: /\.(woff|ttf|woff2|eot|svg|png|jpg)/,
        loader: 'url-loader'
      },
      {
        test: /\.html$/,
        loader: 'raw-loader'
      },
      {
        test: /\.js$/,
        exclude: '/node_modules/',
        loader: 'babel-loader'
      },
      {
        test: /\.jsx$/,
        exclude: '/node_modules/',
        loader: 'babel-loader',
      },
      {
        test: /\.(jsx|js)$/,
        exclude: '/node_modules/',
        loader: 'eslint-loader'
      },
      {
        test: /\.json$/,
        exclude: '/node_modules/',
        loader: 'json-loader'
      }
    ]
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.DefinePlugin({
      __DEV__: true
    }),
    new webpack.LoaderOptionsPlugin({
      debug: true
    }),
    new UglifyJsPlugin({
      beautify: false,
      comment: false,
      compress: {
        warnings: false,
        drop_console: true,
        collapse_vars: true,
        reduce_vars: true
      }
    })
  ],
  devServer: {
    contentBase: 'src/public/',
    historyApiFallback: true,
    publicPath: '/',
    hot: true,
    inline: false,
    // proxy: {
    //   '/api/member/asdfasdf': {
    //     target: '/api/member/loginname',
    //     bypass: function(req, res, proxyOptions) {
    //       console.log(proxyOptions)
    //       res.writeHead(200, {"Content-Type": "application/json"});
    //       res.end(JSON.stringify({loginName: 'Turbidsoul'}));
    //     }
    //   },
    //   '/api/member/authenticate': {
    //     target: 'http://localhost:3000',
    //     bypass: function(req, res, proxyOptions) {
    //       res.writeHead(200, {"Content-Type": "application/json"});
    //       res.end(JSON.stringify({isLogin: true}));
    //     }
    //   }
    // }
  },
};
